package com.honyelchak.shortlink.admin.controller;

import com.honyelchak.shortlink.admin.dto.req.GroupDeleteReqDTO;
import com.honyelchak.shortlink.admin.dto.req.GroupSaveReqDTO;
import com.honyelchak.shortlink.admin.dto.req.GroupSortReqDTO;
import com.honyelchak.shortlink.admin.dto.req.GroupUpdateReqDTO;
import com.honyelchak.shortlink.admin.dto.resp.GroupRespDTO;
import com.honyelchak.shortlink.admin.service.GroupService;
import com.honyelchak.shortlink.base.common.convention.result.Result;
import com.honyelchak.shortlink.base.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody GroupSaveReqDTO reqDTO) {
        groupService.saveGroup(reqDTO.getGroupName());
        return Results.success();
    }

    @GetMapping("/api/short-link/admin/v1/group/list")
    public Result<List<GroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> delete(@RequestBody GroupDeleteReqDTO reqDTO) {
        groupService.delete(reqDTO);
        return Results.success();
    }

    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> update(@RequestBody GroupUpdateReqDTO reqDTO) {
        groupService.update(reqDTO);
        return Results.success();
    }
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sort(@RequestBody List<GroupSortReqDTO> reqDTO) {
        groupService.sort(reqDTO);
        return Results.success();
    }
}
